package org.cpoy.ei.session;

import org.cpoy.eims.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("courseHome")
public class CourseHome extends EntityHome<Course> {

	@In(create = true)
	TeacherHome teacherHome;

	public void setCourseId(Integer id) {
		setId(id);
	}

	public Integer getCourseId() {
		return (Integer) getId();
	}

	@Override
	protected Course createInstance() {
		Course course = new Course();
		return course;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Teacher teacher = teacherHome.getDefinedInstance();
		if (teacher != null) {
			getInstance().setTeacher(teacher);
		}
	}

	public boolean isWired() {
		return true;
	}

	public Course getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Student> getStudents() {
		return getInstance() == null ? null : new ArrayList<Student>(
				getInstance().getStudents());
	}

}
